#include <MdaAudioTonePlayer.h>
#include <eikmenup.h>
#include "TonePlayer.h"
#include "TonePlayerPrivate.h"

CTonePlayerPrivate* CTonePlayerPrivate::NewL(TonePlayer *wrapper)
{
    CTonePlayerPrivate* self = NewLC(wrapper);
    CleanupStack::Pop(self);  
    return self;
}

CTonePlayerPrivate* CTonePlayerPrivate::NewLC(TonePlayer *wrapper)
{
    CTonePlayerPrivate* self = new (ELeave) CTonePlayerPrivate(wrapper);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}

CTonePlayerPrivate::CTonePlayerPrivate(TonePlayer *wrapper):
        iFrequency(2),
        iDuration(500000000),
        q_ptr( wrapper )
{
}

CTonePlayerPrivate::~CTonePlayerPrivate()
{
    delete iToneUtility;
}

void CTonePlayerPrivate::ConstructL()
{
    iToneUtility = CMdaAudioToneUtility::NewL(*this);
    iToneUtility->PrepareToPlayTone(iFrequency,iDuration);
}

void CTonePlayerPrivate::Play()
{	
    iToneUtility->Play();
}

void CTonePlayerPrivate::Stop()
{
    iToneUtility->CancelPlay();
}

void CTonePlayerPrivate::MatoPrepareComplete(TInt aError)
{
    if(aError == KErrNone)
    {
        iToneUtility->SetPriority(EMdaPriorityMin, EMdaPriorityPreferenceQuality);
        iToneUtility->SetVolume( 0);//(iToneUtility->MaxVolume())/2 );
    }
}
 
void CTonePlayerPrivate::MatoPlayComplete(TInt aError)
{
    if(aError = KErrInUse)
    {
        emit q_ptr->soundDeviceInUse();
    }
}
